package com.vincent;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * Created by vincent on 2018/7/27.
 */
public class SendTask implements Runnable {
    private int flag;
    public SendTask(int i) {
        this.flag = i;
    }

    @Override
    public void run() {
        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.131.129:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 10; i++){

            producer.send(new ProducerRecord<String, String>("test-spring-kafka", "key-"+Integer.toString(i), "value-"+Integer.toString(i)+ "--×-"+Integer.valueOf(flag)));
        }
        producer.close();
    }
}
